package com.tanhua.dubbo.job;


import com.tanhua.commons.templates.TencentCloudTemplate;
import com.tanhua.domain.mongo.Sound;
import com.tanhua.dubbo.api.mongo.SoundApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class SoundJob {

    @Autowired
    private SoundApi soundApi;

    @Autowired
    private TencentCloudTemplate tencentCloudTemplate;

    @Scheduled(cron = "0/30 * * * * ?")
    public void autoSoundCheck(){
        //查询所有未审核的taskid
        List<Sound> soundList = soundApi.findTaskIdByCreated();

        if(!soundList.isEmpty()){
            //通过的集合
            List<String> passList = new ArrayList<>();

            //未通过的集合
            List<String> blockList = new ArrayList<>();

            for (Sound sound : soundList) {
                Boolean b = tencentCloudTemplate.soundCheck(sound.getTaskId());

                if(b){
                    //通过放入通过集合
                    passList.add(sound.getTaskId());
                }else {
                    //未通过放入未通过集合
                    blockList.add(sound.getTaskId());
                }
            }

            soundApi.updateList(passList,1);
            soundApi.updateList(blockList,2);
        }
    }
}
